﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BuisnessLayer;

namespace DataEditor.Components
{
    /// <summary>
    /// Interaction logic for SkillInList.xaml
    /// </summary>
    public partial class SkillInList : UserControl
    {

        public EventHandler SkillSelected;
        public EventHandler SkillDeleted;
        private OccupationsOccupationSkill _skill;

        public SkillInList(OccupationsOccupationSkill pSkill)
        {
            InitializeComponent();
            _skill = pSkill;
            if (_skill == null)
                _skill = new OccupationsOccupationSkill();
            if (_skill.SkillIcon != null && _skill.SkillIcon.Length > 0)
                SkillIcon.Source = ImageUtil.BinaryToImageSource(ImageUtil.StringToByteArray(_skill.SkillIcon));
            SkillName.Content = _skill.Name;
        }

        private void UserControl_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (this.SkillSelected != null)
                this.SkillSelected(_skill, null);
            else
                this.SkillSelected(_skill, null);
        }

        private void DeleteSkill_Click(object sender, RoutedEventArgs e)
        {
            if (this.SkillDeleted != null) {
                _skill.AccessLvl ="0";
                this.SkillDeleted(_skill, null);
            }
        }
    }
}
